#ifndef ARM_LINUX_CAMERA_CAPTURE_H
#define ARM_LINUX_CAMERA_CAPTURE_H

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>

#define CAMERA_LOG
#ifdef  CAMERA_LOG
#define LOG(format, ...) \
    printf("[%s:%d] " format "", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define LOG(format, ...) \
    do {   } while (0)
#endif

#define CLEAR(x)        memset(&(x), 0, sizeof(x))
#define TIME_GET(x)     gettimeofday(&x, NULL)
#define TIME_USE(x, y)  (1000000 * (y.tv_sec - x.tv_sec) + y.tv_usec - x.tv_usec)

enum camera_state {
    CAMERA_STATE_CLOSE = 0,
    CAMERA_STATE_OPEN,
    CAMERA_STATE_REQ_BUF,
    CAMERA_STATE_MAP_BUF,
    CAMERA_STATE_STREAM_ON,
};

struct buffer {
    void *start;
    unsigned int length;
};

struct camera_type {
    int fd;
    char *name;
    enum camera_state state;
    unsigned int width;
    unsigned int height;
    struct buffer *buffers;
    unsigned int n_buffers;
};

int camera_init(struct camera_type *camera);

int camera_capture(struct camera_type *camera, char *save);

int camera_close(struct camera_type *camera);

#endif //ARM_LINUX_CAMERA_CAPTURE_H
